﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace CB.KM.ZH.SalOutstockGenerateZeroCostBatchMaintain3
{
   public class LogHelper
    {
        public static Object obj = new object();
        public static string currentPath = AppDomain.CurrentDomain.BaseDirectory;
        public static void CBLog(string txt,string logName= "MatBalance")
        {

            try
            {
                lock (obj)
                {
                    string logDirePath = $@"{currentPath}App_Data/CBLogs/{logName}";
                    if (!Directory.Exists(logDirePath))
                        Directory.CreateDirectory(logDirePath);
                    string logPath = $@"{logDirePath}/{DateTime.Now.ToString("yyyy-MM-dd")}.txt";
                    if (!File.Exists(logPath))
                        File.Create(logPath).Close();
                    using (StreamWriter sw = File.AppendText(logPath))
                    {
                        sw.WriteLine("");
                        sw.WriteLine($@"时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.sss")}");
                        sw.WriteLine(txt);
                        sw.Flush();
                        sw.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
       
            }

        }

    }
}
